﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using org.sablecc.grammars.java_1_5.analysis;
using org.sablecc.grammars.java_1_5.node;

namespace Commander.Parsing.Visitors {
  public class ClassVisitor : DepthFirstAdapter {
    ClassInformation info;
    public ClassInformation Info { get { return info; } }
    bool isSet = false;
    public ClassVisitor() {
      info = new ClassInformation();
    }

    public override void CaseAClassClassMemberDeclaration(AClassClassMemberDeclaration node) {
      //   base.CaseAClassClassMemberDeclaration(node);
      var visitor = new ClassVisitor();
      node.GetClassDeclaration().Apply(visitor);
      Info.InnerClasses.Add(visitor.Info);
    }

    public override void CaseANormalClassDeclaration(ANormalClassDeclaration node) {
      Info.Modifiers = (TypedList)node.GetModifiers();
      Info.Name = node.GetIdentifier().Text;
      base.CaseANormalClassDeclaration(node);
    }

    public override void CaseAMethodDeclaration(org.sablecc.grammars.java_1_5.node.AMethodDeclaration node) {
      var visitor = new MethodVisitor();
      node.Apply(visitor);
      info.Methods.Add(visitor.Info);
      //base.CaseAMethodDeclaration(node);
    }

    public override void CaseAMarkerAnnotation(AMarkerAnnotation node) {
      info.Annotation = node;
      base.CaseAMarkerAnnotation(node);
    }

    public override void CaseAPackageDeclaration(APackageDeclaration node) {
      info.Packages = node.ToString();
      base.CaseAPackageDeclaration(node);
    }

    public override void CaseASingleImportDeclaration(ASingleImportDeclaration node) {
      info.Imports.Add(node);
      base.CaseASingleImportDeclaration(node);
    }

    public override void InAClassBody(org.sablecc.grammars.java_1_5.node.AClassBody node) {
      info.Body = node;
      base.InAClassBody(node);
    }

    public override void CaseAPrimitiveFieldDeclaration(org.sablecc.grammars.java_1_5.node.APrimitiveFieldDeclaration node) {
      info.Fields.Add(node);
      base.CaseAPrimitiveFieldDeclaration(node);
    }

    //get fields in the class + the good stuff about it
    public override void CaseAReferenceFieldDeclaration(org.sablecc.grammars.java_1_5.node.AReferenceFieldDeclaration node) {
      info.Fields.Add(node);
      base.CaseAReferenceFieldDeclaration(node);
    }




  }
}
